﻿namespace ExceptionsHandling
{
    using System;
    using System.IO;

    class PrintFromFileWithException
    {
        // 1.2.11.03. Write a program that enters file name along with its full file path (e.g. C:\WINDOWS\win.ini),
        // reads its contents and prints it on the console. Find in MSDN how to use System.IO.File.ReadAllText(…).
        // Be sure to catch all possible exceptions and print user-friendly error messages.
        
        static void Main()
        {
            string fileWithPath = @"../../App.config";  // Console.ReadLine();
            string asdf = null;

            try
            {
                asdf = File.ReadAllText(fileWithPath);
                Console.WriteLine(asdf);
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("The file is not found.");
            }
            catch (UnauthorizedAccessException)
            {
                Console.WriteLine("You need administrator access for that operation.");
            }
            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("Unavailable directory.");
            }
            catch (PathTooLongException)
            {
                Console.WriteLine("The directory path of the file is too long.");
            }
            catch (IOException)
            {
                Console.WriteLine("Something went wrong with the Input/Output stream.");
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("The file is like nullable, whatever it means.");
            }
            catch (ArgumentException)
            {
                Console.WriteLine("The file is not txt readable.");
            }
            catch (NotSupportedException)
            {
                Console.WriteLine("Exception for hackers.");
            }
            catch (System.Security.SecurityException)
            {
                Console.WriteLine("Exception for NSA.");
            }
            finally
            {
                Console.WriteLine();
                Console.WriteLine("Goodbye!");
                Console.WriteLine();
            }
        }
    }
}